package com.example.hello.POJO;

import com.example.hello.Badge;
import com.example.hello.views.badges.Badges;

public class BadgePOJO extends POJO {

    private String content;
    private String color;

    public BadgePOJO() {
    }

    public BadgePOJO(String content, String name, String color) {
        this.content = content;
        this.name = name;
        this.color = color;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getColor() {
        return color;
    }

    public int[] toHexColor() {
        int[] rgb = new int[3];
        rgb[0] = Integer.parseInt(color.substring(0, 2), 16);
        rgb[1] = Integer.parseInt(color.substring(2, 4), 16);
        rgb[2] = Integer.parseInt(color.substring(4, 6), 16);
        return rgb;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public Badge createBadge() {
        return new Badge(content, getEncodedName(), color);
    }

    public String toString() {
        String str = "Badge:\n";

        str += "    _id: " + _id + "\n";
        str += "    content: " + content + "\n";
        str += "    name: " + name + "\n";
        str += "    color: " + color;

        return str;
    }

    public boolean create() {
        return create(Badges.NAME, this);
    }

    public boolean update() {
        return update(Badges.NAME + "/" + name, this);
    }

}